package com.sinacom.ibuilding.service;

import java.io.Serializable;
import java.sql.SQLException;

import com.ibatis.dao.client.DaoManager;
import com.sinacom.ibuilding.dao.DaoConfig;
import com.sinacom.ibuilding.dao.iface.TransActionDao;


public class TransActionService implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7429033596671084493L;
	private TransActionDao transActionDao;
	public TransActionService(){
		DaoManager daoMrg = DaoConfig.getDaoManager(); 
		this.transActionDao = (TransActionDao) daoMrg.getDao(TransActionDao.class);
	}
	public TransActionService(TransActionDao transActionDao){
		this.transActionDao = transActionDao;
	}
	public void startTransaction() throws SQLException{
		transActionDao.startTransAction();
	}
	public void endTransAction() throws SQLException{
		transActionDao.endTransAction();
	}
	public void commitTransAction() throws SQLException{
		transActionDao.commitTransaction();
	}
	public static void main(String []args) throws SQLException{
		TransActionService transAction = new TransActionService();
	
		try{
			//开始事务
			transAction.startTransaction();
			//提交事务
			transAction.commitTransAction();
		}finally{
			//确保结束一个事务
			    System.out.println("end");
			    transAction.endTransAction();
			    System.out.println("end");
		}	
	}
}

